moved send_socket into chat-misc

This commit is contained in:
Václav Šmejkal 2023-02-21 07:58:12 +01:00
parent 50a3a934d6
commit 7123e88f97
Signed by: ENGO150
GPG Key ID: F6D6DF86242C5A59
3 changed files with 28 additions and 23 deletions
include/chat
src/chat

@ -1,6 +1,6 @@
#ifndef WHY2_CHAT_MISC_H
#define WHY2_CHAT_MISC_H
void send_socket(char *text, int socket); //send socket.... wtf did you expect
#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/misc.h>
#include <arpa/inet.h>
void send_socket(char *text, int socket);
int main(void)
{
int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
@ -64,24 +63,4 @@ int main(void)
free(line);
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);
}