Skip to content

Instantly share code, notes, and snippets.

@codegagan
Forked from anonymous/memoryBlow.c
Created May 16, 2014 22:11
Show Gist options
  • Save codegagan/f4807b6de6e467401b48 to your computer and use it in GitHub Desktop.
Save codegagan/f4807b6de6e467401b48 to your computer and use it in GitHub Desktop.
#include <stdio.h>
//#include <alloc.h>
int main(void){
printf("Check the ram usage and press any to start the process");
getchar();
int c=0;
void *v=NULL;
v=malloc(1);
void (* va[33000]);
printf("Reached till array with size %d\n",sizeof(va));
while(v){
v=malloc(100000);
if(v)memset(v,1,100000);
va[c]=v;
c++;
}
printf("completed with %d cycles",c);
getchar();
return 0;
}
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
int main(void)
{
int sockfd = 0,n = 0;
char recvBuff[1024];
struct sockaddr_in serv_addr;
memset(recvBuff, '0' ,sizeof(recvBuff));
if((sockfd = socket(AF_INET, SOCK_STREAM, 0))< 0)
{
printf("\n Error : Could not create socket \n");
return 1;
}
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(5000);
serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))<0)
{
printf("\n Error : Connect Failed \n");
return 1;
}
while((n = read(sockfd, recvBuff, sizeof(recvBuff)-1)) > 0)
{
recvBuff[n] = 0;
if(fputs(recvBuff, stdout) == EOF)
{
printf("\n Error : Fputs error");
}
printf("\n");
}
if( n < 0)
{
printf("\n Read Error \n");
}
return 0;
}
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
int main(void)
{
int listenfd = 0,connfd = 0;
struct sockaddr_in serv_addr;
char sendBuff[1025];
int numrv;
listenfd = socket(AF_INET, SOCK_STREAM, 0);
printf("socket retrieve success\n");
memset(&serv_addr, '0', sizeof(serv_addr));
memset(sendBuff, '0', sizeof(sendBuff));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(5000);
bind(listenfd, (struct sockaddr*)&serv_addr,sizeof(serv_addr));
if(listen(listenfd, 10) == -1){
printf("Failed to listen\n");
return -1;
}
while(1)
{
connfd = accept(listenfd, (struct sockaddr*)NULL ,NULL); // accept awaiting request
printf("Got client Request: connection Id %d\n",connfd);
strcpy(sendBuff,"C Server running at localhost ... ");
write(connfd, sendBuff, strlen(sendBuff));
close(connfd);
sleep(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment