| 48 int c; |
48 int c; |
| 49 char *result; |
49 char *result; |
| 50 size_t input_index = 0; |
50 size_t input_index = 0; |
| 51 size_t result_size = 80; |
51 size_t result_size = 80; |
| 52 |
52 |
| 53 result = (char *) malloc (result_size); |
53 result = g_malloc (result_size); |
| 54 |
54 |
| 55 while (1) |
55 while (1) |
| 56 { |
56 { |
| 57 char ch; |
57 char ch; |
| 58 if (recv (sock, &ch, 1, 0) < 0) |
58 if (recv (sock, &ch, 1, 0) < 0) |
| 59 fprintf (stderr, "recv() error from proxy server\n"); |
59 fprintf (stderr, "recv() error from proxy server\n"); |
| 60 c = ch; |
60 c = ch; |
| 61 |
61 |
| 62 if (c == EOF) |
62 if (c == EOF) |
| 63 { |
63 { |
| 64 free (result); |
64 g_free (result); |
| 65 |
65 |
| 66 /* It's end of file. */ |
66 /* It's end of file. */ |
| 67 fprintf(stderr, "end of file from server\n"); |
67 fprintf(stderr, "end of file from server\n"); |
| 68 } |
68 } |
| 69 |
69 |
| 72 |
72 |
| 73 result[input_index++] = c; |
73 result[input_index++] = c; |
| 74 while (input_index + 1 >= result_size) |
74 while (input_index + 1 >= result_size) |
| 75 { |
75 { |
| 76 result_size *= 2; |
76 result_size *= 2; |
| 77 result = (char *) realloc (result, result_size); |
77 result = (char *) g_realloc (result, result_size); |
| 78 } |
78 } |
| 79 } |
79 } |
| 80 |
80 |
| 81 if (resultp) |
81 if (resultp) |
| 82 *resultp = result; |
82 *resultp = result; |
| 83 |
83 |
| 84 /* Terminate it just for kicks, but we *can* deal with embedded NULs. */ |
84 /* Terminate it just for kicks, but we *can* deal with embedded NULs. */ |
| 85 result[input_index] = '\0'; |
85 result[input_index] = '\0'; |
| 86 |
86 |
| 87 if (resultp == NULL) |
87 if (resultp == NULL) |
| 88 free (result); |
88 g_free (result); |
| 89 return input_index; |
89 return input_index; |
| 90 } |
90 } |
| 91 |
91 |
| 92 |
92 |
| 93 struct hostent *proxy_gethostbyname(char *host) |
93 struct hostent *proxy_gethostbyname(char *host) |