Hello, I've started writing a client for Gemini protocol, but since I've never been writing networking programs, I find myself at the dead end at the moment. Please could someone help me? When I send a request and get a response, the only thing I have in response is "gemini://" and nothing else. The code is given below: #include <arpa/inet.h> #include <locale.h> #include <netdb.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #define STATUS_CODE_INPUT 10 #define STATUS_CODE_SENSITIVE_INPUT 11 #define STATUS_CODE_SUCCESS 20 #define STATUS_CODE_REDIRECT_TEMP 30 #define STATUS_CODE_REDIRECT_PERM 31 #define STATUS_CODE_TEMP_FAILURE 40 #define STATUS_CODE_SERVER_UNAVAILABLE 41 #define STATUS_CODE_CGI_ERROR 42 #define STATUS_CODE_PROXY_ERROR 43 #define STATUS_CODE_SLOW_DOWN 44 #define STATUS_CODE_PERM_FAILURE 50 #define STATUS_CODE_NOT_FOUND 51 #define STATUS_CODE_GONE 52 #define STATUS_CODE_PROXY_REQUEST_REFUSED 53 #define STATUS_CODE_BAD_REQUEST 59 #define STATUS_CODE_CLIENT_CERT_REQUIRED 60 #define STATUS_CODE_CERT_NO_AUTH 61 #define STATUS_CODE_CERT_NOT_VALID 62 #define GEMINI_PORT 1965 int main() { char *locale; locale = setlocale(LC_ALL, ""); int sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { perror("socket"); exit(1); } char *url = malloc(sizeof(char)*1024); strcpy(url, "gemini://gemini.circumlunar.space/\r\n"); char rec_buf[1029] = {0}; struct hostent *host_entry; host_entry = gethostbyname(url); struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(GEMINI_PORT); addr.sin_addr.s_addr = htonl(INADDR_ANY); int opt = 1; if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) { perror("setsockopt"); exit(1); } if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("bind"); exit(2); } if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("connect"); exit(3); } send(sockfd, url, sizeof(url), 0); recv(sockfd, rec_buf, sizeof(rec_buf), 0); printf("%s\n", rec_buf); close(sockfd); shutdown(sockfd, SHUT_RDWR); free(url); return 0; } -- - <anridellal at yandex.ru>
---
Previous in thread (1 of 5): 🗣️ Paul Warren (pwarren (a) pwarren.id.au)
Next in thread (3 of 5): 🗣️ Kevin Sangeelee (kevin (a) susa.net)