Browse Source

Minor IPv6 tweaks and credit to original author

tags/v0.99.beta20
Sam Hocevar 3 years ago
parent
commit
d5c7775113
3 changed files with 13 additions and 12 deletions
  1. +1
    -0
      NEWS
  2. +1
    -0
      THANKS
  3. +11
    -12
      src/cacaserver.c

+ 1
- 0
NEWS View File

@@ -2,6 +2,7 @@


\section news0_99_beta20 Changes between 0.99.beta20 and 0.99.beta19 \section news0_99_beta20 Changes between 0.99.beta20 and 0.99.beta19


- IPv6 support in cacaserver
- fixed a bug from 2004 that caused PDF documentation generation to fail - fixed a bug from 2004 that caused PDF documentation generation to fail
- memory allocation functions are now more robust - memory allocation functions are now more robust
- numerous fixes for memory leaks and invalid memory accesses: - numerous fixes for memory leaks and invalid memory accesses:


+ 1
- 0
THANKS View File

@@ -5,6 +5,7 @@
- Gildas Bazin <gbazin@netcourrier.com> - win32 driver improvements - Gildas Bazin <gbazin@netcourrier.com> - win32 driver improvements
- Jari Komppa <jari.komppa at gmail> - win32 speed improvements - Jari Komppa <jari.komppa at gmail> - win32 speed improvements
- Bastian Märkisch <bmaerkisch@web.de> - bugfixes and win32 driver improvements - Bastian Märkisch <bmaerkisch@web.de> - bugfixes and win32 driver improvements
- Denis Fondras <ledeuns at github> - IPv6 support in cacaserver


\section thanks2 Reused code \section thanks2 Reused code




+ 11
- 12
src/cacaserver.c View File

@@ -1,6 +1,7 @@
/* /*
* cacaserver Colour ASCII-Art library * cacaserver Colour ASCII-Art library
* Copyright © 2006-2021 Sam Hocevar <sam@hocevar.net> * Copyright © 2006-2021 Sam Hocevar <sam@hocevar.net>
* 2016 Denis Fondras <ledeuns at github>
* 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> * 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved * All Rights Reserved
* *
@@ -100,7 +101,7 @@ struct client
struct sock { struct sock {
int sockfd; int sockfd;
struct sockaddr_in my_addr; struct sockaddr_in my_addr;
};
};


struct server struct server
{ {
@@ -125,7 +126,7 @@ struct server
void (*sigpipe_handler)(int); void (*sigpipe_handler)(int);
}; };


void print_ip(struct sockaddr *ai);
void fprint_ip(FILE *stream, struct sockaddr *ai);
static void manage_connections(struct server *server, int sockfd); static void manage_connections(struct server *server, int sockfd);
static int send_data(struct server *server, struct client *c); static int send_data(struct server *server, struct client *c);
ssize_t nonblock_write(int fd, void *buf, size_t len); ssize_t nonblock_write(int fd, void *buf, size_t len);
@@ -209,7 +210,7 @@ int main(void)
server->socks[server->sock_count].sockfd = fd; server->socks[server->sock_count].sockfd = fd;
server->sock_count++; server->sock_count++;
fprintf(stderr, "listening on "); fprintf(stderr, "listening on ");
print_ip(res->ai_addr);
fprint_ip(stderr, res->ai_addr);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
freeaddrinfo(ai); freeaddrinfo(ai);
@@ -337,7 +338,7 @@ restart:
* XXX: The following functions are local * XXX: The following functions are local
*/ */


void print_ip(struct sockaddr *ai)
void fprint_ip(FILE *stream, struct sockaddr *ai)
{ {
char buffer[INET6_ADDRSTRLEN]; char buffer[INET6_ADDRSTRLEN];
socklen_t len = sizeof(struct sockaddr_in6); socklen_t len = sizeof(struct sockaddr_in6);
@@ -345,15 +346,13 @@ void print_ip(struct sockaddr *ai)
if (ai->sa_family == AF_INET) if (ai->sa_family == AF_INET)
len = sizeof(struct sockaddr_in); len = sizeof(struct sockaddr_in);


int err = getnameinfo(ai, len, buffer, sizeof(buffer), NULL, 0,
NI_NUMERICHOST);
if (err != 0) {
fprintf(stderr, "n/a");
}
fprintf(stderr, "%s",buffer);
int err = getnameinfo(ai, len, buffer, sizeof(buffer), NULL, 0, NI_NUMERICHOST);
if (err != 0)
fprintf(stream, "n/a");
else
fprintf(stream, "%s", buffer);
} }



static void manage_connections(struct server *server, int sockfd) static void manage_connections(struct server *server, int sockfd)
{ {
int fd, flags; int fd, flags;
@@ -365,7 +364,7 @@ static void manage_connections(struct server *server, int sockfd)
return; return;


fprintf(stderr, "[%i] connected from ", fd); fprintf(stderr, "[%i] connected from ", fd);
print_ip((struct sockaddr*)&remote_addr);
fprint_ip(stderr, (struct sockaddr*)&remote_addr);
fprintf(stderr, "\n"); fprintf(stderr, "\n");


/* Non blocking socket */ /* Non blocking socket */


Loading…
Cancel
Save