21 lines
349 B
C
21 lines
349 B
C
|
#include <stdio.h>
|
||
|
#include <sys/socket.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
int main(int argc, char const *argv[])
|
||
|
{
|
||
|
|
||
|
// 创建socket
|
||
|
int socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||
|
if (socket_fd < 0)
|
||
|
{
|
||
|
perror("socket");
|
||
|
return 1;
|
||
|
}
|
||
|
printf("socket 创建成功: %d\n", socket_fd);
|
||
|
|
||
|
close(socket_fd);
|
||
|
|
||
|
return 0;
|
||
|
}
|