Initial commit #1
1 changed files with 34 additions and 0 deletions
34
main.c
Normal file
34
main.c
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include<unistd.h>
|
||||||
|
|
||||||
|
#define error(a) do {} while(0)
|
||||||
|
|
||||||
|
// this is main function
|
||||||
|
int main(
|
||||||
|
// arguments:
|
||||||
|
){
|
||||||
|
int my_soket = socket(AF_INET, SOCK_STREAM, 0)
|
||||||
|
;
|
||||||
|
// https://stackoverflow.com/questions/24194961/how-do-i-use-setsockoptso-reuseaddr
|
||||||
|
// Source - https://stackoverflow.com/a
|
||||||
|
// Posted by Chnossos, modified by community. See post 'Timeline' for change history
|
||||||
|
// Retrieved 2025-12-10, License - CC BY-SA 4.0
|
||||||
|
|
||||||
|
if (setsockopt(my_soket, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) < 0)
|
||||||
|
error("setsockopt(SO_REUSEADDR) failed");
|
||||||
|
|
||||||
|
struct sockaddr_in serv_addr, cli_addr;
|
||||||
|
|
||||||
|
bzero((char *) &serv_addr, sizeof(serv_addr));
|
||||||
|
portno = atoi(argv[1]);
|
||||||
|
serv_addr.sin_family = AF_INET;
|
||||||
|
serv_addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
serv_addr.sin_port = htons(portno);
|
||||||
|
if (bind(my_soket, (struct sockaddr *) &serv_addr,
|
||||||
|
sizeof(serv_addr)) < 0)
|
||||||
|
error("ERROR on binding");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue