blob: 7254f90a71dcb83fc7fe58f8ebf7b788b2b7c04a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include <netinet/in.h>
#include <stdio.h>
#include <sys/socket.h>
int main() {
struct sockaddr_in addr;
addr.sin_family = AF_INET; /* IPv4 */
addr.sin_port = htons(8000); /* Port */
addr.sin_addr.s_addr = INADDR_ANY; /* equals to 0.0.0.0 */
int sfd = socket(AF_INET, SOCK_STREAM, 0);
if (sfd == -1) {
perror("could not open socket");
return 1;
}
int bind_addr = bind(sfd, (struct sockaddr *)&addr, sizeof(addr));
if (bind_addr == -1) {
perror("could not bind socket");
return 1;
}
printf("hello world\n");
return 0;
}
|