summaryrefslogtreecommitdiff
path: root/multipart-replace-http-server.c
diff options
context:
space:
mode:
Diffstat (limited to 'multipart-replace-http-server.c')
-rw-r--r--multipart-replace-http-server.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/multipart-replace-http-server.c b/multipart-replace-http-server.c
index a6a7870..2b30e0f 100644
--- a/multipart-replace-http-server.c
+++ b/multipart-replace-http-server.c
@@ -153,12 +153,12 @@ int sockstream_listen(const char *type, const char *addr) {
struct addrinfo *ai_addr = NULL;
struct addrinfo ai_hints = { 0 };
- char *col = strrchr(addr, ':');
+ char *host = strdupa(addr);
+ char *col = strrchr(host, ':');
if (col == NULL) {
errno = EINVAL;
return -EAI_SYSTEM;
}
- char *host = strdupa(addr);
char *port = &col[1];
*col = '\0';
if (host[0] == '\0')
@@ -169,7 +169,9 @@ int sockstream_listen(const char *type, const char *addr) {
ai_hints.ai_flags = AI_PASSIVE;
int r = getaddrinfo(host, port, &ai_hints, &ai_addr);
- if (r != 0)
+ if (r < 0)
+ return r;
+ if (r > 0)
return -r;
int sock = socket(ai_addr->ai_family, ai_addr->ai_socktype, ai_addr->ai_protocol);
@@ -264,7 +266,7 @@ void usage() {
}
int main(int argc, char *argv[]) {
- if (strcmp(argv[1], "-h") == 0) {
+ if (argc >=2 && strcmp(argv[1], "-h") == 0) {
usage();
return EXIT_SUCCESS;
}
@@ -281,7 +283,7 @@ int main(int argc, char *argv[]) {
error(1, 0, "Opening socket %s %s: %s", argv[1], argv[2], gai_strerror(-sock));
}
- for (int i = 2; i < argc; i++)
+ for (int i = 3; i < argc; i++)
file_add(argv[i]);
signal(SIGPIPE, SIG_IGN);