diff options
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 40 |
1 files changed, 39 insertions, 1 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.103 2016/04/02 14:37:42 krw Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.104 2016/04/06 06:42:17 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -1144,3 +1144,41 @@ sock_set_v6only(int s) | |||
1144 | error("setsockopt IPV6_V6ONLY: %s", strerror(errno)); | 1144 | error("setsockopt IPV6_V6ONLY: %s", strerror(errno)); |
1145 | #endif | 1145 | #endif |
1146 | } | 1146 | } |
1147 | |||
1148 | /* | ||
1149 | * Compares two strings that maybe be NULL. Returns non-zero if strings | ||
1150 | * are both NULL or are identical, returns zero otherwise. | ||
1151 | */ | ||
1152 | static int | ||
1153 | strcmp_maybe_null(const char *a, const char *b) | ||
1154 | { | ||
1155 | if ((a == NULL && b != NULL) || (a != NULL && b == NULL)) | ||
1156 | return 0; | ||
1157 | if (a != NULL && strcmp(a, b) != 0) | ||
1158 | return 0; | ||
1159 | return 1; | ||
1160 | } | ||
1161 | |||
1162 | /* | ||
1163 | * Compare two forwards, returning non-zero if they are identical or | ||
1164 | * zero otherwise. | ||
1165 | */ | ||
1166 | int | ||
1167 | forward_equals(const struct Forward *a, const struct Forward *b) | ||
1168 | { | ||
1169 | if (strcmp_maybe_null(a->listen_host, b->listen_host) == 0) | ||
1170 | return 0; | ||
1171 | if (a->listen_port != b->listen_port) | ||
1172 | return 0; | ||
1173 | if (strcmp_maybe_null(a->listen_path, b->listen_path) == 0) | ||
1174 | return 0; | ||
1175 | if (strcmp_maybe_null(a->connect_host, b->connect_host) == 0) | ||
1176 | return 0; | ||
1177 | if (a->connect_port != b->connect_port) | ||
1178 | return 0; | ||
1179 | if (strcmp_maybe_null(a->connect_path, b->connect_path) == 0) | ||
1180 | return 0; | ||
1181 | /* allocated_port and handle are not checked */ | ||
1182 | return 1; | ||
1183 | } | ||
1184 | |||