Changeset 197 for trunk/src/sh_tools.c
- Timestamp:
- Nov 21, 2008, 10:33:04 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_tools.c
r171 r197 122 122 123 123 #endif 124 125 /* --- check for an interface --- 126 */ 127 int sh_tools_iface_is_present(char *str) 128 { 129 struct sockaddr_in sin; 130 int sd; 131 132 memset(&sin, '\0', sizeof(sin)); 133 sin.sin_family = AF_INET; 134 if (inet_aton(str, &(sin.sin_addr))) 135 { 136 sin.sin_port = htons(2543); 137 138 if (-1 == (sd = socket(AF_INET, SOCK_STREAM, 0))) 139 { 140 return 0; 141 } 142 143 if (-1 == bind(sd, (struct sockaddr *)&sin, sizeof(sin))) 144 { 145 int retval = 0; 146 147 /* bind() fails for access reasons, iface exists 148 */ 149 if (errno == EACCES || errno == EADDRINUSE) 150 retval = 1; 151 close (sd); 152 return retval; 153 } 154 155 /* bind() succeeds, iface exists 156 */ 157 close(sd); 158 return 1; 159 } 160 return 0; 161 } 124 162 125 163 /* --- recode all \blah escapes to '=XX' format, and also code all
Note:
See TracChangeset
for help on using the changeset viewer.