fix
This commit is contained in:
parent
be9d042d64
commit
613d8e6d6c
1
sink/.gitignore
vendored
Normal file
1
sink/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
build/
|
@ -1,12 +1,14 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int sockfd;
|
int sockfd;
|
||||||
struct sockaddr servaddr;
|
struct sockaddr_in servaddr, cliaddr;
|
||||||
|
socklen_t cliaddrlen = sizeof(cliaddr);
|
||||||
|
|
||||||
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
|
||||||
@ -15,13 +17,15 @@ int main() {
|
|||||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
servaddr.sin_port = htons(20169);
|
servaddr.sin_port = htons(20169);
|
||||||
|
|
||||||
bind(sockfd, (SA*) &servaddr, sizeof(servaddr));
|
bind(sockfd, (const struct sockaddr *) &servaddr, sizeof(servaddr));
|
||||||
|
|
||||||
uint8_t buf[1024];
|
uint8_t buf[1024];
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int n = recv(sockfd, buf, sizeof(buf), 0);
|
int n = recvfrom(sockfd, buf, sizeof(buf), 0,
|
||||||
printf("received %d octets\n");
|
(struct sockaddr *) &cliaddr, &cliaddrlen);
|
||||||
|
printf("received %d octets from %04x\n",
|
||||||
|
n, cliaddr.sin_addr.s_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user