moved send_socket into chat-misc
This commit is contained in:
parent
50a3a934d6
commit
7123e88f97
@ -1,6 +1,6 @@
|
|||||||
#ifndef WHY2_CHAT_MISC_H
|
#ifndef WHY2_CHAT_MISC_H
|
||||||
#define WHY2_CHAT_MISC_H
|
#define WHY2_CHAT_MISC_H
|
||||||
|
|
||||||
|
void send_socket(char *text, int socket); //send socket.... wtf did you expect
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -17,11 +17,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <why2/chat/common.h>
|
#include <why2/chat/common.h>
|
||||||
|
#include <why2/chat/misc.h>
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
void send_socket(char *text, int socket);
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
|
int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
|
||||||
@ -64,24 +63,4 @@ int main(void)
|
|||||||
|
|
||||||
free(line);
|
free(line);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
void send_socket(char *text, int socket)
|
|
||||||
{
|
|
||||||
unsigned short text_length = (unsigned short) strlen(text);
|
|
||||||
char *final = why2_calloc(strlen(text) + 2, sizeof(char));
|
|
||||||
|
|
||||||
//SPLIT LENGTH INTO TWO CHARS
|
|
||||||
final[0] = (unsigned) text_length & 0xff;
|
|
||||||
final[1] = (unsigned) text_length >> 8;
|
|
||||||
|
|
||||||
for (int i = 2; i < text_length + 2; i++) //APPEND
|
|
||||||
{
|
|
||||||
final[i] = text[i - 2];
|
|
||||||
}
|
|
||||||
|
|
||||||
//SEND
|
|
||||||
send(socket, final, text_length + 2, 0);
|
|
||||||
|
|
||||||
why2_deallocate(final);
|
|
||||||
}
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
#include <why2/chat/misc.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <why2/memory.h>
|
||||||
|
|
||||||
|
void send_socket(char *text, int socket)
|
||||||
|
{
|
||||||
|
unsigned short text_length = (unsigned short) strlen(text);
|
||||||
|
char *final = why2_calloc(strlen(text) + 2, sizeof(char));
|
||||||
|
|
||||||
|
//SPLIT LENGTH INTO TWO CHARS
|
||||||
|
final[0] = (unsigned) text_length & 0xff;
|
||||||
|
final[1] = (unsigned) text_length >> 8;
|
||||||
|
|
||||||
|
for (int i = 2; i < text_length + 2; i++) //APPEND
|
||||||
|
{
|
||||||
|
final[i] = text[i - 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
//SEND
|
||||||
|
send(socket, final, text_length + 2, 0);
|
||||||
|
|
||||||
|
why2_deallocate(final);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user