336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

using System.Diagnostics;



Stopwatch sw = new Stopwatch();


sw.Start();





// TODO






sw.Stop();






MessageBox.Show(sw.ElapsedMilliseconds.ToString() + "ms");



MessageBox.Show(sw.Elapsed.Hour.ToString() + "Minute");

MessageBox.Show(sw.Elapsed.Minute.ToString() + "Minute");

MessageBox.Show(sw.Elapsed.Second.ToString() + "Minute");







Get Audio Device List

Programming/C# 2017. 12. 27. 11:02 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Get Audio Device List




using System.Management;


        public void getAudioDevice()
        {
            ManagementObjectSearcher objSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_SoundDevice");

            ManagementObjectCollection objCollection = objSearcher.Get();

            foreach (ManagementObject obj in objCollection)
            {
                String str = "";
                foreach (PropertyData property in obj.Properties)
                {
                    str += String.Format("{0}:{1}\n", property.Name, property.Value);
                }
                Console.Out.WriteLine(str + "\n\n");
            }
        }





참조 : https://stackoverflow.com/questions/1525320/how-to-enumerate-audio-out-devices-in-c-sharp

Java JNetPcap Library Packet Capture

Programming/JNetPcap 2016. 9. 20. 13:46 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Java JNetPcap Library Packet Capture 


pcap File




테스트 환경 : Win7 64bit, Eclipse, Java 1.8



이클립스와


자바는 설치되어있다고 가정합니다.





JNetPcap 라이브러리 다운로드


http://jnetpcap.com/download



저는 x84_64



압축을 풀면





jnetpcap.jar, jnetpcap.dll



두 개의 파일이 보입니다.



1. jnetpcap.jar 은 Eclipse 프로젝트에서 참조 할 수 있도록






Package Explorer > Properties > Java Build Path > Libraries > Add JARs 나 Add External JARs 로 추가하여 줍니다.



다운받은 경로보다는


해당 프로젝트 Eclipse Workspace 내에 두는것을 추천합니다.




한글 경로 때문에 안되는 경우도 있습니다,



2. jnetpcap.dll





C:\Windows\System32 경로에 jnetpcap.dll 파일을 복사하여 줍니다.









이제 설정은 끝났습니다.




테스트 코드는 다음과 같습니다.










import java.io.File;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

import org.jnetpcap.ByteBufferHandler;
import org.jnetpcap.Pcap;
import org.jnetpcap.PcapDumper;
import org.jnetpcap.PcapHeader;
import org.jnetpcap.PcapIf;

public class Test1 {
	public static void main(String[] args) {
		// pcap.loop(x, dumpHandler, dumper); x 개 패킷을
		// String ofile = "tmp-capture-file.cap"; tmp-capture-file.cap 파일로 저장


		List alldevs = new ArrayList(); // Will be filled with
														// NICs
		StringBuilder errbuf = new StringBuilder(); // For any error msgs

		/***************************************************************************
		 * First get a list of devices on this system
		 **************************************************************************/
		int r = Pcap.findAllDevs(alldevs, errbuf);
		if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
			System.err.printf("Can't read list of devices, error is %s\n", errbuf.toString());
			return;
		}
		PcapIf device = alldevs.get(0); // We know we have atleast 1 device

		/***************************************************************************
		 * Second we open up the selected device
		 **************************************************************************/
		int snaplen = 64 * 1024; // Capture all packets, no trucation
		int flags = Pcap.MODE_PROMISCUOUS; // capture all packets
		int timeout = 10 * 1000; // 10 seconds in millis
		Pcap pcap = Pcap.openLive(device.getName(), snaplen, flags, timeout, errbuf);
		if (pcap == null) {
			System.err.printf("Error while opening device for capture: %s\n", errbuf.toString());
			return;
		}

		/***************************************************************************
		 * Third we create a PcapDumper and associate it with the pcap capture
		 ***************************************************************************/
		String ofile = "tmp-capture-file.cap";
		PcapDumper dumper = pcap.dumpOpen(ofile); // output file

		/***************************************************************************
		 * Fouth we create a packet handler which receives packets and tells the
		 * dumper to write those packets to its output file
		 **************************************************************************/
		ByteBufferHandler dumpHandler = new ByteBufferHandler() {

			public void nextPacket(PcapHeader arg0, ByteBuffer arg1, PcapDumper arg2) {
				// TODO Auto-generated method stub
				dumper.dump(arg0, arg1);
			}
		};

		/***************************************************************************
		 * Fifth we enter the loop and tell it to capture 10 packets. We pass in
		 * the dumper created in step 3
		 **************************************************************************/
		pcap.loop(10, dumpHandler, dumper);

		File file = new File(ofile);
		System.out.printf("%s file has %d bytes in it!\n", ofile, file.length());

		/***************************************************************************
		 * Last thing to do is close the dumper and pcap handles
		 **************************************************************************/
		dumper.close(); // Won't be able to delete without explicit close
		pcap.close();

		if (file.exists()) {
			// file.delete(); // Cleanup
		}	
	}
}


'Programming > JNetPcap' 카테고리의 다른 글

Java JNetPcap Library Packet Analytics  (0) 2016.09.20

openssl AES encrypt (AES_ctr128_encrypt)

Programming/C,CPP,CS 2016. 9. 19. 08:50 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

openssl AES encrypt (AES_ctr128_encrypt)



Sample Class













AESCTR.cppAESCTR.h


MFC Alert MessageBox2

Programming/MFC 2016. 9. 6. 10:47 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

      int MessageBox(
   LPCTSTR lpszText,
   LPCTSTR lpszCaption = NULL,
   UINT nType = MB_OK 
);

lpszText

가리키는 있는 CString 개체 또는 표시 되는 메시지에 포함 된 null로 끝나는 문자열입니다.

lpszCaption

가리키는 있는 CString 개체 또는 null로 끝나는 문자열에 대 한 캡션을 메시지 상자를 사용할 수 있습니다. 경우 lpszCaption  NULL, 기본 캡션을 "오류"를 사용 합니다.

nType

콘텐츠 및 메시지 상자의 동작을 지정합니다.


전역 함수 사용 AfxMessageBox 응용 프로그램에서 메시지 상자를 구현 하려면이 멤버 함수를 대신 합니다.

다음은 메시지 상자에 사용할 수 있는 다양 한 시스템 아이콘입니다.

중지(x) 아이콘

MB_ICONHANDMB_ICONSTOP, 및 MB_ICONERROR

도움말(?) 아이콘

MB_ICONQUESTION

중요(!) 아이콘

MB_ICONEXCLAMATION 및 MB_ICONWARNING

정보(i) 아이콘

MB_ICONASTERISK 및 MB_ICONINFORMATION









void CMainFrame::OnDisplayErrorMessage()
{
   // This displays a message box with the title "Error"
   // and the message "Help, Something went wrong."
   // The error icon is displayed in the message box, along with
   // an OK button.
   MessageBox(_T("Help, Something went wrong."), _T("Error"), 
      MB_ICONERROR | MB_OK);
}




'Programming > MFC' 카테고리의 다른 글

MFC Dialog Modal  (0) 2016.09.22
MFC Modal and Modeless Dialog Boxes  (0) 2016.09.06
MFC Alert MessageBox  (0) 2016.09.06
MFC Drag And Drop FileName 만 추출  (0) 2016.08.30
MFC File Icon Drag and Drop  (0) 2016.08.30

Apache License, Version 2.0

Programming/C,CPP,CS 2016. 8. 22. 11:24 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Apache License, Version 2.0




http://www.apache.org/licenses/LICENSE-2.0




아파치 라이센스와 같은 라이센스 관련 번역 사이트


https://www.olis.or.kr/ossw/license/license/detail.do?lid=1002&mapcode=010001¤tPage=





 Apache License


Version 2.0, January 2004

http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.

"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:

  1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
  2. You must cause any modified files to carry prominent notices stating that You changed the files; and
  3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
  4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 

    You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS


Winpcap Test 04

Programming/C,CPP,CS 2016. 3. 7. 09:49 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

응용


02,03 Test 를 합친다.


03 에서의 목록으로는 어떤 디바이스가 내가 캡쳐할 디바이스인지를 구분하기가 어렵다.


02에서의 상세정보를 활용하여 정리한다.



 

/*

* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)

* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)

* All rights reserved.

*

* Redistribution and use in source and binary forms, with or without

* modification, are permitted provided that the following conditions

* are met:

*

* 1. Redistributions of source code must retain the above copyright

* notice, this list of conditions and the following disclaimer.

* 2. Redistributions in binary form must reproduce the above copyright

* notice, this list of conditions and the following disclaimer in the

* documentation and/or other materials provided with the distribution.

* 3. Neither the name of the Politecnico di Torino, CACE Technologies 

* nor the names of its contributors may be used to endorse or promote 

* products derived from this software without specific prior written 

* permission.

*

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*

*/


#include <stdio.h>


#include "pcap.h"


#ifndef WIN32

#include <sys/socket.h>

#include <netinet/in.h>

#else

#include <winsock.h>

#endif



// Function prototypes

void ifprint(pcap_if_t *d);

char *iptos(u_long in);

char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen);

void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);



int main()

{

pcap_if_t *alldevs;

pcap_if_t *d;

char errbuf[PCAP_ERRBUF_SIZE+1];

char source[PCAP_ERRBUF_SIZE+1] = {'0'};

int inum;

int i = 0;

pcap_t *adhandle;



if (pcap_findalldevs_ex(source, NULL, &alldevs, errbuf) == -1)

{

fprintf(stderr,"Error in pcap_findalldevs: %s\n",errbuf);

exit(1);

}


/* Scan the list printing every entry */

for(d=alldevs;d;d=d->next)

{

ifprint(d);

i++;

}


printf("Enter the interface number (1-%d):",i);

scanf_s("%d", &inum);



if(inum < 1 || inum > i)

{

printf("\nInterface number out of range.\n");

/* Free the device list */

pcap_freealldevs(alldevs);

return -1;

}


/* Jump to the selected adapter */

for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);





/* Open the device */

if ( (adhandle= pcap_open(d->name,          // name of the device

65536,            // portion of the packet to capture

// 65536 guarantees that the whole packet will be captured on all the link layers

PCAP_OPENFLAG_PROMISCUOUS,    // promiscuous mode

1000,             // read timeout

NULL,             // authentication on the remote machine

errbuf            // error buffer

) ) == NULL)

{

fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);

/* Free the device list */

pcap_freealldevs(alldevs);

return -1;

}


printf("\nlistening on %s...\n", d->description);


/* At this point, we don't need any more the device list. Free it */

pcap_freealldevs(alldevs);


/* start the capture */

pcap_loop(adhandle, 0, packet_handler, NULL);



return 1;

}




/* Print all the available information on the given interface */

void ifprint(pcap_if_t *d)

{

pcap_addr_t *a;

char ip6str[128];


/* Name */

printf("\tName: %s\n",d->name);


/* Description */

if (d->description)

printf("\tDescription: %s\n",d->description);


/* Loopback Address*/

printf("\tLoopback: %s\n",(d->flags & PCAP_IF_LOOPBACK)?"yes":"no");


/* IP addresses */

for(a=d->addresses;a;a=a->next) {

if(a->addr->sa_family != AF_INET)

continue;


printf("\tAddress Family Name: AF_INET\n");

if (a->addr)

printf("\tAddress: %s\n",iptos(((struct sockaddr_in *)a->addr)->sin_addr.s_addr));

if (a->netmask)

printf("\tNetmask: %s\n",iptos(((struct sockaddr_in *)a->netmask)->sin_addr.s_addr));

if (a->broadaddr)

printf("\tBroadcast Address: %s\n",iptos(((struct sockaddr_in *)a->broadaddr)->sin_addr.s_addr));

if (a->dstaddr)

printf("\tDestination Address: %s\n",iptos(((struct sockaddr_in *)a->dstaddr)->sin_addr.s_addr));

}

printf("\n");

}




/* From tcptraceroute, convert a numeric IP address to a string */

#define IPTOSBUFFERS    12

char *iptos(u_long in)

{

static char output[IPTOSBUFFERS][3*4+3+1];

static short which;

u_char *p;


p = (u_char *)&in;

which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1);

_snprintf_s(output[which], sizeof(output[which]), sizeof(output[which]),"%d.%d.%d.%d", p[0], p[1], p[2], p[3]);

return output[which];

}


char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen)

{

socklen_t sockaddrlen;


#ifdef WIN32

sockaddrlen = sizeof(struct sockaddr_in6);

#else

sockaddrlen = sizeof(struct sockaddr_storage);

#endif



if(getnameinfo(sockaddr, 

sockaddrlen, 

address, 

addrlen, 

NULL, 

0, 

NI_NUMERICHOST) != 0) address = NULL;


return address;

}


/* Callback function invoked by libpcap for every incoming packet */

void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)

{

struct tm ltime;

char timestr[16];

time_t local_tv_sec;


/*

* unused variables

*/

(VOID)(param);

(VOID)(pkt_data);


/* convert the timestamp to readable format */

local_tv_sec = header->ts.tv_sec;

localtime_s(&ltime, &local_tv_sec);

strftime( timestr, sizeof timestr, "%H:%M:%S", &ltime);


printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);


}


'Programming > C,CPP,CS' 카테고리의 다른 글

Winpcap Test 06  (0) 2016.03.07
Winpcap Test 05  (0) 2016.03.07
Winpcap Test 03  (0) 2016.03.07
Winpcap Test 02  (0) 2016.03.07
Winpcap Test 01  (0) 2016.03.07

Winpcap Test 03

Programming/C,CPP,CS 2016. 3. 7. 09:11 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Opening an adapter and capturing the packets


#include "pcap.h"

/* prototype of the packet handler */
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);

int main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
int i=0;
pcap_t *adhandle;
char errbuf[PCAP_ERRBUF_SIZE];
    
    /* Retrieve the device list on the local machine */
    if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
    {
        fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
        exit(1);
    }
    
    /* Print the list */
    for(d=alldevs; d; d=d->next)
    {
        printf("%d. %s", ++i, d->name);
        if (d->description)
            printf(" (%s)\n", d->description);
        else
            printf(" (No description available)\n");
    }
    
    if(i==0)
    {
        printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
        return -1;
    }
    
    printf("Enter the interface number (1-%d):",i);
    scanf_s("%d", &inum);
    
    if(inum < 1 || inum > i)
    {
        printf("\nInterface number out of range.\n");
        /* Free the device list */
        pcap_freealldevs(alldevs);
        return -1;
    }
    
    /* Jump to the selected adapter */
    for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
    
    /* Open the device */
    if ( (adhandle= pcap_open(d->name,          // name of the device
                              65536,            // portion of the packet to capture
                                                // 65536 guarantees that the whole packet will be captured on all the link layers
                              PCAP_OPENFLAG_PROMISCUOUS,    // promiscuous mode
                              1000,             // read timeout
                              NULL,             // authentication on the remote machine
                              errbuf            // error buffer
                              ) ) == NULL)
    {
        fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
        /* Free the device list */
        pcap_freealldevs(alldevs);
        return -1;
    }
    
    printf("\nlistening on %s...\n", d->description);
    
    /* At this point, we don't need any more the device list. Free it */
    pcap_freealldevs(alldevs);
    
    /* start the capture */
    pcap_loop(adhandle, 0, packet_handler, NULL);
    
    return 0;
}


/* Callback function invoked by libpcap for every incoming packet */
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)
{
    struct tm ltime;
    char timestr[16];
    time_t local_tv_sec;

    /*
     * unused variables
     */
    (VOID)(param);
    (VOID)(pkt_data);

    /* convert the timestamp to readable format */
    local_tv_sec = header->ts.tv_sec;
    localtime_s(&ltime, &local_tv_sec);
    strftime( timestr, sizeof timestr, "%H:%M:%S", &ltime);
    
    printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);
    
}




'Programming > C,CPP,CS' 카테고리의 다른 글

Winpcap Test 05  (0) 2016.03.07
Winpcap Test 04  (0) 2016.03.07
Winpcap Test 02  (0) 2016.03.07
Winpcap Test 01  (0) 2016.03.07
CPP 2015-01-15 수업내용 정리  (0) 2015.01.15

MediaPlayer Source 선택

Programming/Android 2015. 11. 16. 01:05 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

MediaPlayer Source 선택


res/raw 폴더의 music.mp3 파일


MainActivity 에서 사용한다면


mMediaPlayer = MediaPlayer.create(MainActivity.this, r.raw.music);


File Chooser 를 통해 얻은 경로에 있는 파일을 


MainActivity 에서 사용한다면


mMediaPlayer = new MediaPlayer();

try {

mMediaPlayer.setDataSource(mFilePath);

} catch (Exception e) {

e.printStackTrace();

}


336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Windows 7 환경에서 Android Fulll Source 다운로드 받기


http://source.android.com/source/downloading.html


위 링크에서


안드로이드 전체 소스코드를 다운로드 받을 수 있다.


Windows 환경에서 받는 방법을 설명한다


Cygwin: http://www.cygwin.com

Cygwin 설치 시 추가로 선택해야 할 패키지들: curl, git, python, readline


일단 Cygwin 을 이용하여 Windows 환경에서 리눅스 명령어를 사용 할 수 있게한다.


그 중 위 4개의 명령어는 반드시 필요하다.


Cygwin 홈페이지에서 setup.exe 파일을 다운로드한 후 실행한다.







대부분의 설정은 default 상태로 유지하고 넘어가는데, mirror site 선택할 때는 한국 내에 거주하는 경우 ftp.daum.net 을 선택해주는 것이 가장 빠르게 받을 수 있는 방법이다.



설치해야 할 package를 선택하는 화면이 나오면 우측 상단의 "View" 버튼을 눌러 Full 보기 상태로 만든 후 위에서 언급했던 모듈들을 추가로 선택해준다.


View 버튼은 그림에서 1. 번 위치에 있다.

모듈 설치 선택하는 방법은 그림에서 2. 번 위치를 눌러주는 것으로 결정이 가능하다.

Keep: 이미 설치되어 있는 버전을 그대로 유지할 것임을 나타냄.

Skip: 아직 설치되지 않은 모듈이며 설치하지 않을 것임을 나타냄. 이 부분을 마우스로 클릭하면 버전 번호로 바뀌게 되는데 설치 과정에서 설치하게 될 것임을 나타냄.

Uninstall: 이미 설치되어 있는 모듈을 제거할 것임을 나타냄.






Cygwin 설치가 완료되면


http://source.android.com/source/downloading.html


경로에 있는 대로


Full Source 를 받을 폴더로 Cygwin 에서 경로를 이동하고


curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > repo


repo 를 만든다.


chmod a+x ~/bin/repo


그 다음 repo 의 권한 설정을 변경해주고


repo init -u https://android.googlesource.com/platform/manifest


(위 명령어가 안 먹는 경우 git 설치가 덜 된 경우)

(http://git-scm.com/book/ko/%EC%8B%9C%EC%9E%91%ED%95%98%EA%B8%B0-Git-%EC%84%A4%EC%B9%98)

(위 링크로 들어가서 git 설치 후 진행)


repo 를 초기화 한 후


repo sync


repo sync 를 호출하게 되면 약 1시간 이상동안 android full source 를 다운로드 받게 된다.


중간에 이름과 이메일을 물어보는 질문이 있다.