| /* |
| * Copyright 2015-2016 Rivoreo |
| * |
| * This program is free software; you can redistribute it and/or modify it |
| * under the terms of the GNU General Public License as published by the |
| * Free Software Foundation, either version 2 of the License, or (at your |
| * option) any later version. |
| * |
| * This program is distributed in the hope that it will be useful, but WITHOUT |
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| * more details. |
| */ |
| |
| #define DEFAULT_PORT 3446 |
| |
| #include <sys/types.h> |
| #include <sys/socket.h> |
| #include <netinet/in.h> |
| #include <arpa/inet.h> |
| #include <stdio.h> |
| #include <errno.h> |
| #include <string.h> |
| #include <stdint.h> |
| |
| int main(int argc, char **argv) { |
| int port = DEFAULT_PORT; |
| int fd = socket(AF_INET, SOCK_STREAM, 0); |
| if(fd == -1) { |
| perror("socket"); |
| return 1; |
| } |
| struct sockaddr_in listen_addr = { .sin_family = AF_INET }; |
| //memset(&listen_addr, 0, sizeof listen_addr); |
| //inet_pton(AF_INET, "0.0.0.0", &servaddr.sin_addr); |
| listen_addr.sin_addr.s_addr = htonl(INADDR_ANY); |
| listen_addr.sin_port = htons(port); |
| |
| while(bind(fd, (struct sockaddr *)&listen_addr, sizeof listen_addr) < 0) { |
| if(errno == EAGAIN || errno == EINTR) continue; |
| perror("bind"); |
| return 1; |
| } |
| |
| while(1) { |
| } |
| } |