2269 /*
2270 * 获取源IP地址端口
2271 */
2272 #if 1
2273 void socket_ntop(struct sockaddr *sa, char ipinfo[])
2274 {
2275 char portstr[7];
2276 static char str[128];
2277
2278 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
2279
2280 switch (sa->sa_family) {
2281 case AF_INET: /* IPv4 */
2282 inet_ntop(AF_INET, &sin->sin_addr, str, (socklen_t)sizeof(str));
2283
2284 if (ntohs(sin->sin_port) != 0) {
2285 snprintf(portstr, sizeof(portstr), ":%d", ntohs(sin->sin_port));
2286 strcat(str, portstr);
2287 }
2288 }
2289
2290 //dbg_out(DBG_INFO, "str: %s\n", str);
2291
2292 strncpy(ipinfo, str, strlen(str));
2293 }
2294 #endif
linux UDP通讯 获取源IP地址端口信息
最新推荐文章于 2022-09-13 16:15:59 发布