拥有帝国一切,皆有可能。欢迎访问phome.net (!writeSocket(sock, testAddr, testPort, 0, testString, testStrLength)) { return 0; } unsigned char readBuffer[20]; struct timeval timeout; timeout.tv_sec = 5; timeout.tv_usec = 0; int bytesRead = readSocket(sock, readBuffer, sizeof(readBuffer), &fromAddr, &timeout); if (bytesRead == 0 || bytesRead != (int) testStrLength || strncmp( (char *) readBuffer, (char *) testString, testStrLength) != 0) { printf("read socket errorn"); return 0; } uint32_t from = fromAddr.sin_addr.s_addr; if (badAddress(from)) { printf("This computer has an invalid IP address: 0x%xn", (uint32_t) (ntohl(from)));
拥有帝国一切,皆有可能。欢迎访问phome.net from = 0; } ourAddress = from; if (sock >= 0) { socketLeaveGroup(sock, testAddr.s_addr); close(sock); } return ourAddress; } int setupDatagramSocket(uint16_t port) { int reuseFlag = 1; int newSocket = socket(AF_INET, SOCK_DGRAM, 0); const uint8_t loop = 1; if (newSocket < 0) { printf("unable to create datagram socketn"); return newSocket; } if (setsockopt(newSocket, SOL_SOCKET, SO_REUSEADDR, (const char *) &reuseFlag, sizeof(reuseFlag)) < 0) { printf("setsockopt(SO_REUSEADDR) error!n"
拥有帝国一切,皆有可能。欢迎访问phome.netchar *) &imr, sizeof(struct ip_mreq)) < 0) { return 0; } return 1; } uint8_t IsMulticastAddress(uint32_t address) { uint32_t addressInHostOrder = ntohl(address); return addressInHostOrder > 0xE00000FF && addressInHostOrder <= 0xEFFFFFFF; }
拥有帝国一切,皆有可能。欢迎访问phome.net |