Skip to content

Commit b9de5e7

Browse files
committed
Fixed Small Mistake in C Examples for UDP: PF_INET instead of AF_INET
My examples for UDP under C created sockets using AF_INET instead of PF_INET. Although both have the same value, the right thing to use should be PF_INET.
1 parent c8455d0 commit b9de5e7

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

sockets/c/UDPClient_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
int main(int argc, char *argv[]) {
88
int client; struct sockaddr_in address; char data;
99

10-
client = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); //Allocate client socket
10+
client = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); //Allocate client socket
1111

1212
memset(&address, 0, sizeof(address)); //Clear socket address
1313
address.sin_family = AF_INET; //IPv4 address

sockets/c/UDPClient_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int main(int argc, char *argv[]) {
66
WSADATA wsaData; char data;
77

88
WSAStartup(MAKEWORD(2, 0), &wsaData); //Initialize WinSock
9-
client = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); //Allocate client socket
9+
client = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); //Allocate client socket
1010

1111
memset(&address, 0, sizeof(address)); //Clear socket address
1212
address.sin_family = AF_INET; //IPv4 address

sockets/c/UDPServer_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int main(int argc, char *argv[]) {
1616
serverAddr.sin_port = htons(9998); //serve at port 9998
1717
addrSize = sizeof(clientAddr);
1818

19-
server = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); //Allocate UDP socket
19+
server = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); //Allocate UDP socket
2020
bind(server, (struct sockaddr *) &serverAddr, sizeof(serverAddr)); //(*@\serverBox{1)}@*)
2121

2222
for (j = 5; (--j) >= 0;) {

sockets/c/UDPServer_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main(int argc, char *argv[]) {
1414
addrSize = sizeof(clientAddr);
1515

1616
WSAStartup(MAKEWORD(2, 0), &wsaData); //Initialize WinSock
17-
server = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);//Allocate UDP socket
17+
server = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);//Allocate UDP socket
1818
bind(server, (struct sockaddr *) &serverAddr, sizeof(serverAddr)); //(*@\serverBox{1)}@*)
1919

2020
for (j = 5; (--j) >= 0;) {

0 commit comments

Comments
 (0)